package bsk_dac.accesscontrol;

import java.util.EnumMap;
import java.util.Map;

/**
 * Klasa reprezentuje prawa dostępu do jednej tabeli w postacilisty booleanów.
 *
 */
public class TableAccess extends Access {

    static public TableAccess getAllDisabledAccess() {
        TableAccess access = new TableAccess();
        return access;
    }

    @Override
    public String toString() {
        String result = "";
        result = "SELECT "+privileges.get(AccessType.SELECT)+" <"+userGivePermission.get(AccessType.SELECT)+"> | "
                + "UPDATE "+privileges.get(AccessType.UPDATE)+" <"+userGivePermission.get(AccessType.UPDATE)+"> | "
                + "DELETE "+privileges.get(AccessType.DELETE)+" <"+userGivePermission.get(AccessType.DELETE)+"> | "
                + "INSERT "+privileges.get(AccessType.INSERT)+" <"+userGivePermission.get(AccessType.INSERT)+"> ";

        return result;
    }

    public void fillAccessPrivileges(boolean select, boolean update, boolean insert, boolean delete) {
        privileges.put(AccessType.SELECT, select);
        privileges.put(AccessType.UPDATE, update);
        privileges.put(AccessType.INSERT, insert);
        privileges.put(AccessType.DELETE, delete);

        userGivePermission.put(AccessType.SELECT, true);
        userGivePermission.put(AccessType.UPDATE, true);
        userGivePermission.put(AccessType.INSERT, true);
        userGivePermission.put(AccessType.DELETE, true);
    }

    protected void fillAccessDefaultPrivileges() {
        privileges.put(AccessType.SELECT, Boolean.FALSE);
        privileges.put(AccessType.DELETE, Boolean.FALSE);
        privileges.put(AccessType.UPDATE, Boolean.FALSE);
        privileges.put(AccessType.INSERT, Boolean.FALSE);

        userGivePermission.put(AccessType.SELECT, false);
        userGivePermission.put(AccessType.UPDATE, false);
        userGivePermission.put(AccessType.INSERT, false);
        userGivePermission.put(AccessType.DELETE, false);
    }
}
